<template>
  <h3 style="margin-bottom: 20px">导出数据</h3>
  <el-button type="primary" @click="export1">员工表</el-button>
  <el-button type="primary" @click="export2">菜品表</el-button>
  <el-button type="primary" @click="export3">会员表</el-button>
</template>

<script setup>
import {listCuisinesProApi, listEmployeeConditionApi, listVIPApi} from "../../api";
import JsExportExcel from "js-export-excel"

async function export1() {
  const {data} = await (await listEmployeeConditionApi(0,99999)).json()
  let options = {
    fileName:"员工表",
    datas:[
      {
        sheetData:data.content,
        sheetName: "sheet",
        sheetHeader: ["ID", "姓名","性别","生日","职位","基本工资","入职时间","离职时间","是否离职"],
      }
    ]
  }
  let te = new JsExportExcel(options)
  te.saveExcel()
}
async function export2() {
  let cuisines = await (await listCuisinesProApi()).json()
  let data = cuisines.data
  for(let i=0;i<data.length;i++) {
    delete data[i].image
    delete data[i].imageType
  }
  let options = {
    fileName:"菜品表",
    datas:[
      {
        sheetData:data,
        sheetName: "sheet",
        sheetHeader: ["ID", "菜名","价格","描述"],
      }
    ]
  }
  let te = new JsExportExcel(options)
  te.saveExcel()
}

async function export3() {
  let vips = await (await listVIPApi()).json()
  let data = vips.data
  for(let i=0;i<data.length;i++) {
    delete data[i].grade
    delete data[i].integration
  }
  let options = {
    fileName:"会员表",
    datas:[
      {
        sheetData:data,
        sheetName: "sheet",
        sheetHeader: ["ID", "姓名","性别","联系方式"],
      }
    ]
  }
  let te = new JsExportExcel(options)
  te.saveExcel()
}
</script>

<style scoped>

</style>